package com.lailai.domainservice.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @Author lgr
 * @Date 2025/9/15
 * @Email 983105834@qq.com
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MultiResponse<T> extends Response {
    private int total;
    private Collection<T> data;

    public static <T> MultiResponse<T> ofLong(Collection<T> data, long total) {
        return of(data, (int) total);
    }

    public static <T> MultiResponse<T> of(Collection<T> data, int total) {
        MultiResponse<T> response = new MultiResponse<T>();
        response.setSuccess(true);
        response.setData(data);
        response.setTotal(total);
        return response;
    }

    public static <T> MultiResponse<T> ofWithoutTotal(Collection<T> data) {
        return of(data, 0);
    }

    public static <T> MultiResponse<T> ofEmpty() {
        return of(new ArrayList(0), 0);
    }
}
